# Cleaning the Work Environment ####
rm(list=ls(all=T))
gc()

getwd()

#### Sample Representativeness ####
###### Tables 1 to 12 in the Online Appendices ####

#####Age Groups ####

s1_age <- c(79.4,
            14.1,
            5.0,
            1.4,
            0.2)

s2_age <- c(76.0,
            16.4,
            4.7,
            2.3,
            0.6)

s3_age <- c(3.9,
            6.8,
            20.2,
            55.4,
            13.7)

tr_2018_age <- c(15.3,
                 21.3,
                 30.1,
                 21.1,
                 12.3)

tr_2019_age <- c(15.2,
                 21.0,
                 30.1,
                 21.1,
                 12.6)

age_s1_tr_2018 <- cbind(s1_age, tr_2018_age)
row.names(age_s1_tr_2018) <- c("18-24","25-34", "35-49", "50-64","65+")

age_s2_tr_2018 <- cbind(s2_age, tr_2018_age)
row.names(age_s2_tr_2018) <- c("18-24","25-34", "35-49", "50-64","65+")

age_s3_tr_2019 <- cbind(s3_age, tr_2019_age)
row.names(age_s3_tr_2019) <- c("18-24","25-34", "35-49", "50-64","65+")

chisq.test(age_s1_tr_2018 )
round(chisq.test(age_s1_tr_2018 )$stdres, 2)
round(rcompanion::cramerV(age_s1_tr_2018), 2)

chisq.test(age_s2_tr_2018)
round(chisq.test(age_s2_tr_2018)$stdres, 2)
round(rcompanion::cramerV(age_s2_tr_2018), 2)

chisq.test(age_s3_tr_2019)
round(chisq.test(age_s3_tr_2019)$stdres, 2)
round(rcompanion::cramerV(age_s3_tr_2019), 2)

##### Gender Groups ####

s1_gender <- c(39.0, #male
               59.6) #female

s2_gender <- c(33.4,
               64.7)

s3_gender <- c(57.8,
               42.0)

tr_2018_gender <- c(49.2,
                    50.8)

tr_2019_gender <- c(49.2,
                    50.8)

gender_s1_tr_2018 <- cbind(s1_gender, tr_2018_gender)
row.names(gender_s1_tr_2018) <- c("Male","Female")

gender_s2_tr_2018 <- cbind(s2_gender, tr_2018_gender)
row.names(gender_s2_tr_2018) <- c("Male","Female")

gender_s3_tr_2019 <- cbind(s3_gender, tr_2019_gender)
row.names(gender_s3_tr_2019) <- c("Male","Female")

chisq.test(gender_s1_tr_2018 )
round(rcompanion::cramerV(gender_s1_tr_2018), 2)

chisq.test(gender_s2_tr_2018)
round(rcompanion::cramerV(gender_s2_tr_2018), 2)

chisq.test(gender_s3_tr_2019)
round(rcompanion::cramerV(gender_s3_tr_2019), 2)

##### Education Group ####

s1_education <- c(2.6, 73.5, 22.2, 1.8)

s2_education <- c(2.89, 70.06, 25.99, 1.06)

s3_education <- c(12, 32.2, 55.9)

tr_2018_education <- c(47.9, 24.2, 18, 0.7)

tr_2019_education <- c(46.8, 25.1, 18.9)

education_s1_tr_2018 <- cbind(s1_education, tr_2018_education)
row.names(education_s1_tr_2018) <- c("Below High School Graduate",
                                     "High School Graduate",
                                     "College Graduate or Above",
                                     "Unknown")

education_s2_tr_2018 <- cbind(s2_education, tr_2018_education)
row.names(education_s2_tr_2018) <- c("Below High School Graduate",
                                     "High School Graduate",
                                     "College Graduate or Above",
                                     "Unknown")

education_s3_tr_2019 <- cbind(s3_education, tr_2019_education)
row.names(education_s3_tr_2019) <- c("Below High School Graduate",
                                     "High School Graduate",
                                     "College Graduate or Above")

chisq.test(education_s1_tr_2018 )
round(chisq.test(education_s1_tr_2018 )$stdres, 2)
round(rcompanion::cramerV(education_s1_tr_2018), 2)

chisq.test(education_s2_tr_2018)
round(chisq.test(education_s2_tr_2018)$stdres, 2)
round(rcompanion::cramerV(education_s2_tr_2018), 2)

chisq.test(education_s3_tr_2019)
round(chisq.test(education_s3_tr_2019)$stdres, 2)
round(rcompanion::cramerV(education_s3_tr_2019), 2)

##### Geographical Distribution ####

s1_geo <- c(0.6,
            0.6,
            0.4,
            0.8,
            0.2,
            0.6,
            1.8,
            6.6,
            0.8,
            0.4,
            0.2,
            0.2,
            0.2,
            0.4,
            0,
            0,
            0.2,
            0.4,
            0.2,
            0.2,
            0,
            0,
            0,
            0,
            0.2,
            0.2,
            0.2,
            0.2,
            0.2,
            0,
            0.4,
            0.2,
            1,
            0.2,
            0.4,
            4,
            0.6,
            3.4,
            40.4,
            0.4,
            1,
            1.8,
            0.2,
            0.2,
            4.4,
            5,
            0,
            0.2,
            0,
            0,
            0,
            0,
            0,
            0,
            0.2,
            0.2,
            1.8,
            0.4,
            0.2,
            0.6,
            0.2,
            0,
            0,
            1.8,
            0.2,
            11.3,
            0.8,
            0.2,
            0.2,
            0.2,
            0.2,
            0.2,
            0.2,
            0,
            0,
            0,
            0.6,
            0.6,
            0.2,
            0.2,
            0.2)

tr_2018_geo <- c(1.9,
                 1.4,
                 0.9,
                 1.3,
                 0.7,
                 0.5,
                 1.3,
                 5.7,
                 1.7,
                 0.8,
                 0.5,
                 0.4,
                 0.4,
                 0.3,
                 0.4,
                 0.5,
                 1,
                 1.1,
                 0.7,
                 0.3,
                 0.3,
                 0.4,
                 0.4,
                 0.1,
                 1,
                 1,
                 0.6,
                 0.4,
                 0.2,
                 0.2,
                 1.3,
                 0.5,
                 1.1,
                 0.3,
                 0.4,
                 3.8,
                 0.3,
                 2.4,
                 18.7,
                 1.3,
                 1.8,
                 2.3,
                 0.6,
                 0.6,
                 2.7,
                 3,
                 0.3,
                 0.2,
                 0.5,
                 0.1,
                 0.1,
                 0.3,
                 0.9,
                 0.3,
                 1.9,
                 1.8,
                 2.2,
                 0.8,
                 0.5,
                 0.6,
                 0.2,
                 0.7,
                 0.3,
                 2.7,
                 0.3,
                 6.9,
                 1.7,
                 0.8,
                 0.7,
                 0.4,
                 0.3,
                 0.3,
                 0.3,
                 0.2,
                 0.5,
                 0.8,
                 1.7,
                 1.3,
                 0.7,
                 0.6,
                 0.5)

geo_s1_tr_2018 <- cbind(s1_geo, tr_2018_geo)
row.names(geo_s1_tr_2018) <- c("Manisa",
                               "Aydin",
                               "Afyon",
                               "Mugla",
                               "Kutahya",
                               "Usak",
                               "Denizli",
                               "Izmir",
                               "Kayseri",
                               "Sivas",
                               "Aksaray",
                               "Nevsehir",
                               "Nigde",
                               "Kirsehir",
                               "Kirikkale",
                               "Yozgat",
                               "Malatya",
                               "Van",
                               "Elazig",
                               "Hakkari",
                               "Bingol",
                               "Bitlis",
                               "Mus",
                               "Tunceli",
                               "Ordu",
                               "Trabzon",
                               "Giresun",
                               "Rize",
                               "Artvin",
                               "Gumushane",
                               "Sakarya",
                               "Duzce",
                               "Eskisehir",
                               "Bilecik",
                               "Bolu",
                               "Bursa",
                               "Yalova",
                               "Kocaeli",
                               "Istanbul",
                               "Kahramanmaras",
                               "Hatay",
                               "Mersin",
                               "Isparta",
                               "Osmaniye",
                               "Adana",
                               "Antalya",
                               "Burdur",
                               "Igdir",
                               "Agri",
                               "Ardahan",
                               "Bayburt",
                               "Erzincan",
                               "Erzurum",
                               "Kars",
                               "Sanliurfa",
                               "Diyarbakir",
                               "Gaziantep",
                               "Mardin",
                               "Sirnak",
                               "Batman",
                               "Kilis",
                               "Adiyaman",
                               "Siirt",
                               "Konya",
                               "Karaman",
                               "Ankara",
                               "Samsun",
                               "Tokat",
                               "Corum",
                               "Amasya",
                               "Bartin",
                               "Karabuk",
                               "Sinop",
                               "Cankiri",
                               "Kastamonu",
                               "Zonguldak",
                               "Balikesir",
                               "Tekirdag",
                               "Canakkale",
                               "Edirne",
                               "Kirklareli")

chisq.test(geo_s1_tr_2018)
round(chisq.test(geo_s1_tr_2018)$stdres, 2)
round(rcompanion::cramerV(geo_s1_tr_2018), 2)

s2_geo <- c(0.2,
            0.6,
            1.1,
            0.3,
            0,
            1.2,
            0.6,
            8.1,
            0.8,
            0.2,
            0,
            0,
            0.2,
            0.2,
            0.2,
            0.2,
            0.3,
            0.6,
            0,
            0,
            0,
            0.5,
            0.2,
            0.2,
            0,
            0,
            0.5,
            0,
            0.2,
            0.3,
            1.4,
            0,
            0.8,
            0.8,
            0.3,
            3.7,
            0.5,
            0.5,
            45.1,
            0.3,
            0.2,
            0,
            0,
            2,
            0.5,
            2.9,
            4,
            0,
            0.2,
            0,
            0,
            0,
            0.2,
            0.3,
            0,
            0.6,
            1.2,
            0,
            0,
            0.5,
            0.3,
            0.2,
            0.2,
            2.4,
            0,
            9.9,
            0,
            0.2,
            1.1,
            0,
            0.3,
            0,
            0,
            0.2,
            0.5,
            0.5,
            0.5,
            0.2,
            0.2,
            1.5,
            0.5)

tr_2018_geo <- c(1.3,
                 1.4,
                 1.9,
                 0.9,
                 0.5,
                 1.3,
                 0.7,
                 5.7,
                 1.7,
                 0.8,
                 0.5,
                 0.4,
                 0.5,
                 0.4,
                 0.4,
                 0.3,
                 1,
                 1.1,
                 0.4,
                 0.4,
                 0.3,
                 0.7,
                 0.3,
                 0.1,
                 1,
                 0.6,
                 1,
                 0.2,
                 0.4,
                 0.2,
                 2.4,
                 0.5,
                 1.3,
                 1.1,
                 0.4,
                 3.8,
                 0.3,
                 0.3,
                 18.7,
                 1.8,
                 1.3,
                 0.6,
                 0.3,
                 2.3,
                 0.6,
                 2.7,
                 3,
                 0.9,
                 0.5,
                 0.2,
                 0.1,
                 0.1,
                 0.3,
                 0.3,
                 1.9,
                 1.8,
                 2.2,
                 0.7,
                 0.5,
                 0.8,
                 0.6,
                 0.3,
                 0.2,
                 2.7,
                 0.3,
                 6.9,
                 0.7,
                 0.8,
                 1.7,
                 0.5,
                 0.8,
                 0.3,
                 0.2,
                 0.3,
                 0.4,
                 0.3,
                 1.3,
                 0.6,
                 0.5,
                 1.7,
                 0.7)

geo_s2_tr_2018 <- cbind(s2_geo, tr_2018_geo)
row.names(geo_s2_tr_2018) <- c("Mugla",
                               "Aydin",
                               "Manisa",
                               "Afyon",
                               "Usak",
                               "Denizli",
                               "Kutahya",
                               "Izmir",
                               "Kayseri",
                               "Sivas",
                               "Aksaray",
                               "Nigde",
                               "Yozgat",
                               "Kirikkale",
                               "Nevsehir",
                               "Kirsehir",
                               "Malatya",
                               "Van",
                               "Bitlis",
                               "Mus",
                               "Hakkari",
                               "Elazig",
                               "Bingol",
                               "Tunceli",
                               "Ordu",
                               "Giresun",
                               "Trabzon",
                               "Gumushane",
                               "Rize",
                               "Artvin",
                               "Kocaeli",
                               "Duzce",
                               "Sakarya",
                               "Eskisehir",
                               "Bolu",
                               "Bursa",
                               "Bilecik",
                               "Yalova",
                               "Istanbul",
                               "Hatay",
                               "Kahramanmaras",
                               "Isparta",
                               "Burdur",
                               "Mersin",
                               "Osmaniye",
                               "Adana",
                               "Antalya",
                               "Erzurum",
                               "Agri",
                               "Igdir",
                               "Ardahan",
                               "Bayburt",
                               "Kars",
                               "Erzincan",
                               "Sanliurfa",
                               "Diyarbakir",
                               "Gaziantep",
                               "Adiyaman",
                               "Sirnak",
                               "Mardin",
                               "Batman",
                               "Siirt",
                               "Kilis",
                               "Konya",
                               "Karaman",
                               "Ankara",
                               "Corum",
                               "Tokat",
                               "Samsun",
                               "Kastamonu",
                               "Zonguldak",
                               "Sinop",
                               "Cankiri",
                               "Bartin",
                               "Amasya",
                               "Karabuk",
                               "Tekirdag",
                               "Edirne",
                               "Kirklareli",
                               "Balikesir",
                               "Canakkale")

chisq.test(geo_s2_tr_2018)
round(chisq.test(geo_s2_tr_2018)$stdres, 2)
round(rcompanion::cramerV(geo_s2_tr_2018), 2)

s3_geo <- c(0.2,
            0.5,
            0.2,
            0.5,
            1.5,
            2.5,
            2,
            11,
            0.7,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0.5,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0.2,
            0.2,
            0.2,
            0.5,
            0,
            0,
            0,
            1.5,
            0.7,
            0.7,
            0.2,
            1.2,
            4.7,
            0,
            0,
            29.4,
            0.5,
            1.7,
            1.7,
            3.9,
            4.9,
            0,
            0,
            0,
            0.2,
            0.2,
            0.2,
            0,
            0,
            0,
            0,
            0.5,
            0.5,
            0.5,
            0,
            0,
            0,
            0,
            0,
            0,
            2.2,
            0.2,
            16.7,
            0.7,
            0.2,
            0.2,
            1.7,
            0.7,
            0,
            0,
            0,
            0,
            0.2,
            1.7,
            0,
            0,
            0)

tr_2019_geo <- c(1.4,
                 1.3,
                 0.5,
                 0.7,
                 0.9,
                 1.8,
                 1.3,
                 5.7,
                 1.7,
                 0.5,
                 0.4,
                 0.3,
                 0.4,
                 0.8,
                 0.5,
                 0.4,
                 1,
                 0.3,
                 0.4,
                 0.7,
                 0.3,
                 0.4,
                 0.1,
                 1.1,
                 1,
                 1,
                 0.6,
                 0.5,
                 0.2,
                 0.3,
                 0.2,
                 2.4,
                 1.3,
                 1.1,
                 0.3,
                 0.5,
                 3.8,
                 0.4,
                 0.3,
                 18.5,
                 1.3,
                 2.2,
                 1.9,
                 2.7,
                 3,
                 0.3,
                 0.6,
                 0.6,
                 0.9,
                 0.3,
                 0.3,
                 0.5,
                 0.1,
                 0.1,
                 0.2,
                 2.2,
                 1.9,
                 1.8,
                 0.7,
                 0.6,
                 0.2,
                 0.8,
                 0.3,
                 0.5,
                 2.7,
                 0.3,
                 6.9,
                 0.8,
                 0.3,
                 0.3,
                 1.7,
                 0.4,
                 0.7,
                 0.5,
                 0.3,
                 0.8,
                 1.7,
                 1.3,
                 0.7,
                 0.5,
                 0.5)

geo_s3_tr_2019 <- cbind(s3_geo, tr_2019_geo)
row.names(geo_s3_tr_2019) <- c("Aydin",
                               "Denizli",
                               "Usak",
                               "Kutahya",
                               "Afyon",
                               "Manisa",
                               "Mugla",
                               "Izmir",
                               "Kayseri",
                               "Aksaray",
                               "Kirikkale",
                               "Kirsehir",
                               "Nevsehir",
                               "Sivas",
                               "Yozgat",
                               "Nigde",
                               "Malatya",
                               "Bingol",
                               "Bitlis",
                               "Elazig",
                               "Hakkari",
                               "Mus",
                               "Tunceli",
                               "Van",
                               "Ordu",
                               "Trabzon",
                               "Giresun",
                               "Rize",
                               "Artvin",
                               "Bartin",
                               "Gumushane",
                               "Kocaeli",
                               "Sakarya",
                               "Eskisehir",
                               "Bilecik",
                               "Duzce",
                               "Bursa",
                               "Bolu",
                               "Yalova",
                               "Istanbul",
                               "Kahramanmaras",
                               "Mersin",
                               "Hatay",
                               "Adana",
                               "Antalya",
                               "Burdur",
                               "Isparta",
                               "Osmaniye",
                               "Erzurum",
                               "Erzincan",
                               "Kars",
                               "Agri",
                               "Ardahan",
                               "Bayburt",
                               "Igdir",
                               "Gaziantep",
                               "Sanliurfa",
                               "Diyarbakir",
                               "Adiyaman",
                               "Batman",
                               "Kilis",
                               "Mardin",
                               "Siirt",
                               "Sirnak",
                               "Konya",
                               "Karaman",
                               "Ankara",
                               "Zonguldak",
                               "Cankiri",
                               "Karabuk",
                               "Samsun",
                               "Amasya",
                               "Corum",
                               "Kastamonu",
                               "Sinop",
                               "Tokat",
                               "Balikesir",
                               "Tekirdag",
                               "Canakkale",
                               "Edirne",
                               "Kirklareli")

chisq.test(geo_s3_tr_2019)
round(chisq.test(geo_s3_tr_2019)$stdres, 2)
round(rcompanion::cramerV(geo_s3_tr_2019), 2)